﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office;
using System.Reflection;
//using M

namespace PowerTest.GiaoVien
{
    public partial class frmXemCacDeThiDaTao : Form
    {
        public frmXemCacDeThiDaTao()
        {
            InitializeComponent();
        }

        private void frmXemCacDeThiDaTao_Load(object sender, EventArgs e)
        {                     
                        // TODO: This line of code loads data into the 'powerTestDataSet.tblDeThi' table. You can move, or remove it, as needed.
            this.tblDeThiTableAdapter.Fill(this.powerTestDataSet.tblDeThi);

        }

        private void dgvNoiDungDe_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvNoiDungDe.CurrentRow == null)
            {
                return;
            }
            try
            {
                string maCauHoi = dgvNoiDungDe.CurrentRow.Cells["maCauHoiDataGridViewTextBoxColumn"].Value.ToString();
                tblChiTietDapAnTableAdapter.FillByByMCH(powerTestDataSet.tblChiTietDapAn, maCauHoi);
            }
            catch
            {
            }
        }

        private void dgvDeThi_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvDeThi.CurrentRow == null)
            {
                return;
            }
            try
            {
                string maDe = dgvDeThi.CurrentRow.Cells["maDeDataGridViewTextBoxColumn"].Value.ToString();
                
                this.viewDeThiTableAdapter.FillByMaDe(this.powerTestDataSet.viewDeThi,maDe);
            }
            catch
            {
            }
        }
        /*
        private Document doc;
        private ApplicationClass app;
        private void app_ApplicationEvents2_Even_NewDocument(Document Doc)
        {
            doc = Doc;
            doc.FormattingShowNumbering = true;
            PageSetup pageSetup = doc.PageSetup;
            pageSetup.BottomMargin = 40f;
            pageSetup.LeftMargin = 40f;
            pageSetup.PaperSize = WdPaperSize.wdPaperA4;
            pageSetup.RightMargin = 20f;
            pageSetup.TopMargin = 40f;
            pageSetup.HeaderDistance = 20f;
            pageSetup.FooterDistance = 20f;
            doc.PageSetup = pageSetup;
        }
        private void Load_Word()
        {
            app = new ApplicationClass();
            app.Visible = true;
            app.Activate();
            app.Caption = "@ Vũ Hoàng Lâm - zCopPerHeaDz";
            //app.ApplicationEvents2_Event_add_NewDocument(new ApplicationEvents2_NewDocumentEventHandler(app_ApplicationEvents2_Even_NewDocument));
        }
        private void Mo_Word()
        {
            try
            {
                object wdNewBlankDocument = WdNewDocumentType.wdNewBlankDocument;
                object template = Missing.Value;
                object visible = true;
                app.Documents.Add(ref template,ref template,ref template,ref wdNewBlankDocument,ref visible);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message,"Lỗi",MessageBoxButtons.OK,MessageBoxIcon.Hand);
                Load_Word();
            }
        }
        */

        private void btXuatFile_Click(object sender, EventArgs e)
        {/*
            FolderBrowserDialog dialog = new FolderBrowserDialog
            {
                RootFolder = Environment.SpecialFolder.MyComputer
            };
            if (dialog.ShowDialog() == DialogResult.OK)
            {
                string selectedPath = dialog.SelectedPath;
                int length = selectedPath.LastIndexOf(@"\");
                if (length == (selectedPath.Length - 1))
                {
                    selectedPath = selectedPath.Substring(0, length);
                }

            }     
          * ---------------------------------------------
            try
            {
                SaveFileDialog dialog = new SaveFileDialog
                {
                    RestoreDirectory = true,
                    Title = "Chọn đường dẫn để lưu File!",
                    Filter = "Word File (*.doc, *.docx, *.rtf)|*.doc; *.docx; *.rtf"
                };
                dialog.ShowDialog();
                Load_Word();
                Mo_Word();
                int stt= 0;
                foreach (DataGridViewRow row in dgvNoiDungDe.Rows)
                {
                    stt++;


                }
            }
            catch { throw; }
            */
            MessageBox.Show("Chức năng chưa hoàn thiện!");
        }

        private void btThoat_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void btXemDe_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Chức năng chưa hoàn thiện!");
        }
    }
}
